package org.example.forum.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.forum.common.AppResult;
import org.example.forum.exception.ApplicationException;
import org.springframework.web.bind.annotation.*;

@Tag(name = "测试类的相关接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @Operation(summary ="测试接口1，测试环境")
    @GetMapping("/t")
    public String test(){
        System.out.println("测试");
        return "测试成功";
    }

    @Operation(summary ="测试接口2，显示抛出的异常信息")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception...");
    }

    @Operation(summary ="测试接口4，显示抛出的自定义异常")
    @GetMapping("/appException")
    public AppResult testApplicationException(){
        throw new ApplicationException("这是一个applicationException...");
    }

    @Operation(summary ="测试接口4，按传入的姓名显示信息")
    @PostMapping("/helloByName")
    public AppResult helloByName (@Parameter(description = "姓名") @RequestParam("name")  String name) {
        return AppResult.success("hello : " + name);
    }
}
